package com.github.wxpay.sdk;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Slf4j
public class WxConfigCustom extends WXPayConfig {
    private String certFilePath;
    private String APP_ID;
    private String MCH_ID;
    private String KEY;

    public WxConfigCustom(String APP_ID, String MCH_ID, String KEY) {
        this.APP_ID = APP_ID;
        this.MCH_ID = MCH_ID;
        this.KEY = KEY;
    }

    public void setCertFilePath(String certFilePath) {
        this.certFilePath = certFilePath;
    }

    @Override
    String getAppID() {
        return this.APP_ID;
    }

    @Override
    String getMchID() {
        return this.MCH_ID;
    }

    @Override
    String getKey() {
        return this.KEY;
    }

    @Override
    InputStream getCertStream() {
        try {
            return new FileInputStream(certFilePath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            log.info("找不到证书文件 => {}", e.getMessage());
        }
        return null;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        return new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
    }
}
